package com.zzxx.wechat.service.impl;

import com.zzxx.wechat.common.vo.ArcteryxSwitchReq;
import com.zzxx.wechat.common.vo.ArcteryxSwitchVo;
import com.zzxx.wechat.dao.ArcteryxSwitchDao;
import com.zzxx.wechat.entity.ArcteryxSwitch;
import com.zzxx.wechat.service.ArcteryxSwitchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class ArcteryxSwitchServiceImpl implements ArcteryxSwitchService {


    @Resource
    private ArcteryxSwitchDao arcteryxSwitchDao;

    public ArcteryxSwitchVo queryByConfigName(ArcteryxSwitchReq req) {
        ArcteryxSwitchVo arcteryxSwitchVo = new ArcteryxSwitchVo();
        ArcteryxSwitch arcteryxSwitch = arcteryxSwitchDao.queryByConfigName(req.getConfigName());

        if (arcteryxSwitch == null) {
            arcteryxSwitchVo.setConfigSwitch(0);
            return arcteryxSwitchVo;
        }
        arcteryxSwitchVo.setConfigSwitch(arcteryxSwitch.getConfigSwitch());

        return arcteryxSwitchVo;
    }


    public void changeByConfigName(String configName, Integer configSwitch) {

        ArcteryxSwitch arcteryxSwitch = arcteryxSwitchDao.queryByConfigName(configName);

        if (arcteryxSwitch == null) {
            arcteryxSwitch = new ArcteryxSwitch();
            arcteryxSwitch.setConfigName(configName);
        }
        arcteryxSwitch.setConfigSwitch(configSwitch);

        arcteryxSwitchDao.saveOrUpdate(arcteryxSwitch);
    }


}
